$(function(){

  let type = location.search.split("&")[0].split("=")[0].slice(1)
  let id = location.search.split("&")[0].split("=")[1]
  let spec = location.search.split("&")[1].split("=")[1]
  let color = location.search.split("&")[2].split("=")[1]
  let $num = $(".number").html()
  let $price = $(".mz-price")
  $.ajax({
    url:`http://127.0.0.1:8080/mz/carSpec/${type}&${id}&${spec}`,
    type:"get",
    dataType:"json",
    success:function(result){
      // console.log(result.title);
      // console.log(result.spec);
      // console.log(result.price);
      $(".title").html(result.title)
      $(".spec").html(result.spec)
      $price.html(`￥${result.price}`)
      $(".price").html(`￥${$price.html().slice(1)*$num}`)
      $(".sum").html(`￥${$price.html().slice(1)*$num}.00`)
    }
  })
  $.ajax({
    url:`http://127.0.0.1:8080/mz/carColor/${type}&${id}&${color}`,
    type:"get",
    dataType:"json",
    success:function(result){
      // console.log(result.pic_spec);
      $(".cart-body-img img").attr("src",result.m1)
      $(".color").html(result.pic_spec)
    }
  })
  
  // 数量加减
  $(".add").click(function(){
    $num++
    $(".number").html($num)
    $(".price").html(`￥${$price.html().slice(1)*$num}`)
    $(".sum").html(`￥${$price.html().slice(1)*$num}.00`)
  })
  $(".jian").click(function(){
    if($num>1){
      $num--
      $(".number").html($num)
      $(".price").html(`￥${$price.html().slice(1)*$num}`)
      $(".sum").html(`￥${$price.html().slice(1)*$num}.00`)
    }
  })

  // 全选框功能
  $(".JSelectAll").click(function(){
    let $checked = $('input[type="checkbox"]')
    console.log($checked);
    if($(this).prop("checked")){
      $checked.prop("checked",true)
    }else{
      $checked.prop("checked",false)
    }
  })
  $('input[type="checkbox"]:not(.JSelectAll)').click(function(){
    if(!$(this).prop("checked")){
    $('.JSelectAll').prop("checked",false)

    }
  })
})
